require(["config"],function(){
    require(["jquery","header"],function($){
        function Register(){
            console.log(1);
            this.addListener();
        }

        $.extend(Register.prototype,{
            constructor: Register,
            addListener:function(){
                console.log(1);
                $(".register-form").on("submit",$.proxy(this.registerHandler,this));
                $(".close-btn").on("click",this.closeAlert);
            },
            registerHandler: function(data){

                var phone = $(".phone").val();

                if(!(/^1[34578]\d{9}$/.test(phone))){
                    console.log
                    $(".alert").fadeIn(1000);
                }else{
                    var data = $(".register-form").serialize();
                    // console.log(data);
                    var url = "http://localhost/LIZI/api/register.php";
    
                    $.post(url,data,this.regSuccessHandler,"json");
                }
                return false;

            },

            regSuccessHandler: function(data){
                if(data.res_code === 1){
                    location = "/html/login.html";
                }
                else{
                    $(".reg-error").removeClass("hidden");
                }
            },

            closeAlert: function(){
                $(".alert").fadeOut(500);
            }
        });

        new Register();
    });
});